package me.zingon.self.bigdispatcher.exception;

import lombok.extern.slf4j.Slf4j;
import me.zingon.self.bigdispatcher.dto.R;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

import javax.validation.ConstraintViolationException;

/**
 * @author ztc 1423047407@qq.com
 * @version 1.0
 * @date 2020-12-29 16:15
 */
@RestControllerAdvice
@Slf4j
public class MyExceptionHandler {
    @ExceptionHandler(ConstraintViolationException.class)
    public Object constraintViolationException(ConstraintViolationException se){
        log.error(se.getMessage(),se);
        return se.getMessage();
    }

    @ExceptionHandler(ServiceException.class)
    public Object serviceException(ServiceException se){
        log.error(se.getMessage(),se);
        return R.failed(se.getMsg());
    }

    @ExceptionHandler(Exception.class)
    public Object exception(Exception se){
        log.error(se.getMessage(),se);
        return R.failed(se.getMessage());
    }

}
